﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;
using System.Collections;
using System.Diagnostics;

namespace MySimpleWCFService
{
    /// <summary>
    /// Diagnostics
    /// Author: alep@ciklum.net
    /// </summary>
    internal static class Diagnostic
    {
        #region Fields
        private static EventLog appLog = null;
        #endregion

        #region Properies
        public static EventLog AppLog
        {
            get
            {
                if (appLog == null)
                    appLog = new System.Diagnostics.EventLog();
                appLog.Source = "MySimpleWCFService";
                return appLog;
            }
        }
        #endregion

        #region Methods 
        /// <summary>
        /// Write trace message
        /// </summary>
        /// <param name="message">Message</param>
        public static void Trace(string message)
        {
            Trace(message, EventLogEntryType.Information);
        }

        /// <summary>
        /// Write trace message
        /// </summary>
        /// <param name="message">Message</param>
        /// <param name="entryType">Message Type</param>
        public static void Trace(string message, EventLogEntryType entryType)
        {
            AppLog.WriteEntry(message, entryType);
        }

        /// <summary>
        /// Write error to trace log
        /// </summary>
        /// <param name="exception">Exception object</param>
        public static void TraceError(Exception exception)
        {
            string message = exception.Message;
            if (exception.InnerException != null)
                message += "(InnerException:" + exception.InnerException;
            AppLog.WriteEntry(message, EventLogEntryType.Error);
        }

        #endregion
    }
}
